package zheng.mockit.samples.http;

import zheng.mockit.AbstractMockitTestCase;
import zheng.mockit.PluginConf;
import zheng.mockit.compare.IMessageCompare;
import zheng.mockit.plugin.http.MockitHttpClient;
import zheng.mockit.plugin.http.message.MockitHttpResponseMessage;

/**
 * Created by zcz on 16-7-29.
 */
public class HttpGetExample1 extends AbstractMockitTestCase {


    @PluginConf("{\"method\":\"get\", \"url\":\"http://www.baidu.com\"}")
    private MockitHttpClient mockitHttpClient;

    @Override
    protected void runTC() {
        //1.调起一个请求。
        mockitHttpClient.sendRequest(null);

        //2.验证客户端返回结果。
        mockitHttpClient.assertResponse("<title>百度一下，你就知道</title>", new IMessageCompare() {
            @Override
            public void compare(Object expected, Object message) {
                MockitHttpResponseMessage responseMessage = (MockitHttpResponseMessage) message;
                org.junit.Assert.assertEquals("HTTP状态码异常", 200, responseMessage.getStatusCode());;
                org.junit.Assert.assertTrue("百度首页显示异常", responseMessage.getContent().toString().indexOf(expected.toString()) != -1);
            }
        });
    }
}
